import { defineConfig } from 'vitepress';
import { mermaidPlugin } from './theme/mermaid-plugin.js';
import mdTasklist from 'markdown-it-task-lists';
import { withSidebar } from 'vitepress-sidebar';

const vitePressConfigs = {
  title: 'j-tronic',
  description: 'a modern frontend and backend development framework',
  publicDir: '.vitepress/public',
  head: [['link', { rel: 'icon', href: '/favicon.ico' }]],

  // themeConfig 中的 sidebar 会被 withSidebar 自动生成和填充
  themeConfig: {
    nav: [{ text: '首页', link: '/README' }],
  },

  rewrites: {
    'README.md': 'index.md',
  },

  markdown: {
    config: (md) => {
      md.use(mermaidPlugin);
      md.use(mdTasklist);
    },
  },

  vite: {
    optimizeDeps: {
      include: ['mermaid'],
    },
    ssr: {
      noExternal: ['mermaid'],
    },
  },
};

export default defineConfig(
  withSidebar(vitePressConfigs, {
    collapsed: true,
    collapseDepth: 2,
    rootGroupCollapsed: false,
  })
);
